package com.itheima.demo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class DateDemo {
    public static void main(String[] args) throws ParseException {
        System.out.println("请输入您的出生日期:[yyyy-MM-dd 例如:2000-11-11]");
        String strBirthday = new Scanner(System.in).nextLine();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //将出生日期转换为Date对象
        Date birthday = sdf.parse(strBirthday);
        //通过getTime获得Date对象的毫秒值
        long birthdaytime = birthday.getTime();
        //获得当前时间距离时间原点的毫秒值
        Date newDate = new Date();
        long newDateTime = newDate.getTime();
        long day = (newDateTime - birthdaytime)/1000/60/60/24;
        System.out.println("从"+strBirthday+"到现在,你已经活了"+day+"天!");
    }
}
